//
//  WRGestureClickView.m
//  WRGesturePassword
//
//  Created by 王然 on 16/6/27.
//  Copyright © 2016年 wangran. All rights reserved.
//

#import "WRGestureClickView.h"

@interface WRGestureClickView()

@property (nonatomic , strong) UIView * smallView;

@property (nonatomic , strong) UIColor * normalColor;

@property (nonatomic , strong) UIColor * selectColor;

@property (nonatomic , strong) UIColor * wrongColor;

@end

@implementation WRGestureClickView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self updateSelfUI];
        
    }
    return self;
} 
- (void)reloadNormallColor:(UIColor *)normalC withSelelctColor:(UIColor *)selectC withWrongColor:(UIColor *)wrongC
{
    self.normalColor = normalC;
    self.selectColor = selectC;
    if(wrongC)self.wrongColor = wrongC;
    self.layer.borderColor = self.normalColor.CGColor;
    
}
- (void)updateSelfUI
{
    self.backgroundColor = [UIColor clearColor];
    self.layer.cornerRadius = self.frame.size.width / 2;
    self.layer.masksToBounds = YES;
    self.layer.borderWidth = 0.5;
    
    CGFloat smallVR = 15;
    self.smallView  = [[UIView alloc]initWithFrame:CGRectMake((self.frame.size.width - smallVR) / 2, (self.frame.size.width - smallVR) / 2 , smallVR, smallVR)];
    self.smallView.layer.cornerRadius = smallVR / 2;
    self.smallView.layer.masksToBounds = YES;
    self.smallView.backgroundColor = [UIColor clearColor];
    [self addSubview:self.smallView];
    
}
- (void)setSelected:(BOOL)selected
{
    _selected = selected;
    [self reloadStateAndSelectColor];
}
- (void)setStateType:(View_Click_Type)stateType
{
    _stateType = stateType;
    [self reloadStateAndSelectColor];
}
- (void)reloadStateAndSelectColor
{
    self.backgroundColor = [UIColor clearColor];
    if (self.selected) {
        switch (self.stateType) {
            case View_Click_Type_Right:
                self.layer.borderColor = self.selectColor.CGColor;
                self.smallView.backgroundColor = self.selectColor;
                break;
            case View_Click_Type_Wrong:
                if (self.wrongColor)self.layer.borderColor = self.wrongColor.CGColor;
                if (self.wrongColor)self.smallView.backgroundColor = self.wrongColor;
                break;
            case View_Click_Type_RightAll:
                self.backgroundColor = self.selectColor;
                self.smallView.backgroundColor = [UIColor clearColor];
                self.layer.borderColor = [UIColor clearColor].CGColor;
                break;
            case View_Click_Type_Normal:
                self.backgroundColor = [UIColor clearColor];
                self.smallView.backgroundColor = [UIColor clearColor];
                self.layer.borderColor = self.normalColor.CGColor;
                break;
            default:
                break;
        }
        
    }else
    {
        self.layer.borderColor = self.normalColor.CGColor;
        self.smallView.backgroundColor = [UIColor clearColor];
    }

}

@end
